﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Tools
{
    public partial class ProjectGenerate : Form
    {
        public ProjectGenerate()
        {
            InitializeComponent();
        }

        private void txt_path_TextChanged(object sender, EventArgs e)
        {

        }

        private void btn_generate_Click(object sender, EventArgs e)
        {
            var rootPath = this.txt_path.Text;
            var _title = this.txt_title.Text;
            string[] folderNames = { "Const", "Entity", "Enum", "Service", "Option", "Utils", "Attribute", "SeedData" };

            if (_title.Length < 0 || rootPath.Length < 0)
            {
                MessageBox.Show("创建失败，请检查路径及标题");
            }
            else
            {
                try
                {
                    // 遍历数组中的每个文件夹名称
                    foreach (string folderName in folderNames)
                    {
                        // 组合完整的文件夹路径
                        string folderPath = Path.Combine(rootPath, _title, folderName);
                        // 创建文件夹
                        CreateFolder(folderPath);
                    }

                    string openFolderPath = Path.Combine(rootPath, _title);
                    if (Directory.Exists(openFolderPath))
                    {
                        // 使用 Process.Start 方法打开文件夹
                        Process.Start("explorer.exe", openFolderPath);
                    }
                    else
                    {
                        Console.WriteLine($"文件夹 {openFolderPath} 不存在。");
                    }

                }
                catch (Exception ex)
                {
                    //  Console.WriteLine($"发生错误: {ex.Message}");
                }






            }
        }

        static void CreateFolder(string folderPath)
        {

            //string[] folderNames = { "Const", "Entity", "Enum", "Service", "Option", "Utils", };
            //try
            //{
            //    // 遍历数组中的每个文件夹名称
            //    foreach (string folderName in folderNames)
            //    {
            //        // 组合完整的文件夹路径
            //        string folderPath = Path.Combine(rootPath, folderName);
            //        // 创建文件夹
            //        CreateFolder(folderPath);
            //    }
            //    MessageBox.Show("文件夹创建成功");
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show($"发生错误: {ex.Message}");
            //}

            if (!Directory.Exists(folderPath))
            {
                // 创建文件夹
                Directory.CreateDirectory(folderPath);
            }
            else
            {
                MessageBox.Show($"文件夹 {folderPath} 已存在。");
            }


        }
    }
}
